import express from 'express';
import config from './helpper/config';
// 数据库初始化
import './database/mongo';
const env = process.env.NODE_ENV
console.log('env: ', env);
const app = express();
app.use(express.json());
//文档地址
app.use('/documents',express.static(__dirname+'/documents'))

// 404路由捕获
app.get('*', function (req, res) {
  console.log('Not Found');
  res.sendStatus(404);
});
// 全局错误处理
app.use((err, req, res, next) => {
  if (res.headersSent) {
    return next(err);
  }
  res.status(500);
  res.render('error', { error: err });
});
console.log('config[env]: ', config[env]);
app.listen(config[env]?.port, () => {
  
  console.log("serve is starting  :"+config[env]?.port);
});

